﻿<navigation:Page 
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  
           x:Class="AdminModule.Views.ViewAnswerLog" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
           xmlns:converter="clr-namespace:AdminModule.Converters"
           xmlns:usercontrols="clr-namespace:AdminModule.UserControls.Common"
           xmlns:classes="clr-namespace:AdminModule.CustomXAMLElements"
           xmlns:ansLog="clr-namespace:AdminModule.AnswerLog"
           xmlns:root="clr-namespace:AdminModule"
           xmlns:dataPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
           d:DesignWidth="640" d:DesignHeight="480"
           Loaded="Page_Loaded">
    <navigation:Page.Resources>
        <converter:DateTimeConverter x:Key="dateTimeConverter" />
        <converter:AnswerLogImagesConverter x:Key="answerLogImagesConverter" />
        <converter:AnswerLogHintsConverter x:Key="answerLogHintsConverter"></converter:AnswerLogHintsConverter>
        <converter:RoundConverter x:Key="roundConverter"></converter:RoundConverter>
        <converter:AnswerLogColorsConverter x:Key="answerLogColorsConverter"></converter:AnswerLogColorsConverter>
        <root:Settings x:Key="settings"></root:Settings>

        <ansLog:MarginConverter x:Key="mc"/>
        <ansLog:BoolToVisibilityConverter x:Key="vc"/>

        <classes:ColumnCollection x:Key="AnswerLog">
            <!--<data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn.HeaderStyle>
                    <Style TargetType="dataprimitives:DataGridColumnHeader">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border BorderThickness="0,0,1,0" BorderBrush="#ffc9caca">
                                        <Grid>
                                            <Grid.Background>
                                                <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.015"/>
                                                    <GradientStop Color="#F9FFFFFF" Offset="0.274"/>
                                                    <GradientStop Color="#E5FFFFFF" Offset="0.309"/>
                                                    <GradientStop Color="#FFD1D1D1" Offset="1"/>
                                                    <GradientStop Color="#FFDDE1E5" Offset="0.722"/>
                                                    <GradientStop Color="#FFDADEE2" Offset="0.983"/>
                                                </LinearGradientBrush>
                                            </Grid.Background>
                                            <CheckBox ToolTipService.ToolTip="Отметить все" x:Name="commonCheckBox" Checked="commonCheckBox_Checked" Unchecked="commonCheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                        </Grid>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </data:DataGridTemplateColumn.HeaderStyle>

                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox ToolTipService.ToolTip="Удалить" Loaded="CheckBox_Loaded" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" Tag="{Binding}"></CheckBox>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Margin="5,0,5,0" Source="{Binding Path=Item.Operation, Converter={StaticResource answerLogImagesConverter}}" ToolTipService.ToolTip="{Binding Path=Item.Operation, Converter={StaticResource answerLogHintsConverter}}"></Image>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Дата и время">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock VerticalAlignment="Center" ToolTipService.ToolTip="число.месяц.год, часы:минуты">
                            <TextBlock.Text>
                                <Binding Path="Item.CurrentTime" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd.MM.yy, HH:mm" />
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Пользователь">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Item.UserName}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Показатель / градации">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel VerticalAlignment="Center" Orientation="Vertical">
                            <TextBlock Width="390" TextWrapping="Wrap" FontWeight="Bold" Text="{Binding Path=Item.Characteristic.Name}" />
                            <ListBox BorderThickness="0" ItemsSource="{Binding Path=Item.Gradations}" Background="Transparent" BorderBrush="Transparent">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <CheckBox ToolTipService.ToolTip="Удалить" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Tag="{Binding}"></CheckBox>
                                            <TextBlock Width="390" TextWrapping="Wrap" Text="{Binding}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Сотрудник">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Item.Respondent.Person.ShortFIO}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Отдел">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock ToolTipService.ToolTip="{Binding Path=Item.Respondent.Department.Name}" Text="{Binding Path=Item.Respondent.Department.Abbriviation}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Значение">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Item.Volume, Converter={StaticResource roundConverter}, ConverterParameter='2'}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Tag="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" ToolTipService.ToolTip="История изменений" Width="24" Height="24" x:Name="historyButton" Click="historyButton_Click">
                            <Image Source="/AdminModule;Component/Images/History.png"></Image>
                        </Button>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>-->
            <data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn.HeaderStyle>
                    <Style TargetType="dataprimitives:DataGridColumnHeader">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border BorderThickness="0,0,1,0" BorderBrush="#ffc9caca">
                                        <Grid>
                                            <Grid.Background>
                                                <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.015"/>
                                                    <GradientStop Color="#F9FFFFFF" Offset="0.274"/>
                                                    <GradientStop Color="#E5FFFFFF" Offset="0.309"/>
                                                    <GradientStop Color="#FFD1D1D1" Offset="1"/>
                                                    <GradientStop Color="#FFDDE1E5" Offset="0.722"/>
                                                    <GradientStop Color="#FFDADEE2" Offset="0.983"/>
                                                </LinearGradientBrush>
                                            </Grid.Background>
                                            <CheckBox ToolTipService.ToolTip="Отметить все для удаления" x:Name="commonCheckBox" Checked="commonCheckBox_Checked" Unchecked="commonCheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                        </Grid>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </data:DataGridTemplateColumn.HeaderStyle>

                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox ToolTipService.ToolTip="Отметить для удаления" Loaded="CheckBox_Loaded" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" Tag="{Binding}"></CheckBox>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Margin="5,0,5,0" Source="{Binding Path=Operation, Converter={StaticResource answerLogImagesConverter}}" ToolTipService.ToolTip="{Binding Path=Operation, Converter={StaticResource answerLogHintsConverter}}"></Image>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Дата и время">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock VerticalAlignment="Center" ToolTipService.ToolTip="число.месяц.год, часы:минуты">
                            <TextBlock.Text>
                                <Binding Path="CurrentTime" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd.MM.yy, HH:mm" />
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Пользователь">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=UserName}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Показатель / градации">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel VerticalAlignment="Center" Orientation="Vertical">
                            <TextBlock Width="390" TextWrapping="Wrap" FontWeight="Bold" Text="{Binding Path=Characteristic.Name}" />
                            <ListBox BorderThickness="0" ItemsSource="{Binding Path=Gradations}" Background="Transparent" BorderBrush="Transparent">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <CheckBox ToolTipService.ToolTip="Удалить" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Tag="{Binding}"></CheckBox>
                                            <TextBlock Width="390" TextWrapping="Wrap" Text="{Binding}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Градации" Visibility="Collapsed">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel VerticalAlignment="Center" Orientation="Vertical">
                            <ListBox BorderThickness="0" ItemsSource="{Binding Path=Gradations}" Background="Transparent" BorderBrush="Transparent">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <CheckBox ToolTipService.ToolTip="Удалить" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Tag="{Binding}"></CheckBox>
                                            <TextBlock Width="390" TextWrapping="Wrap" Text="{Binding}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Сотрудник">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Respondent.Person.ShortFIO}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Отдел">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock ToolTipService.ToolTip="{Binding Path=Respondent.Department.Name}" Text="{Binding Path=Respondent.Department.Abbriviation}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="Значение">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Volume, Converter={StaticResource roundConverter}, ConverterParameter='2'}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            <data:DataGridTemplateColumn Header="">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Tag="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,0" ToolTipService.ToolTip="История изменений" Width="24" Height="24" x:Name="historyButton" Click="historyButton_Click">
                            <Image Source="/AdminModule;Component/Images/History.png"></Image>
                        </Button>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

        </classes:ColumnCollection>

        <classes:ColumnCollection x:Key="InputLog">
            <data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn.HeaderStyle>
                    <Style TargetType="dataprimitives:DataGridColumnHeader">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border BorderThickness="0,0,1,0" BorderBrush="#ffc9caca">
                                        <Grid>
                                            <Grid.Background>
                                                <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.015"/>
                                                    <GradientStop Color="#F9FFFFFF" Offset="0.274"/>
                                                    <GradientStop Color="#E5FFFFFF" Offset="0.309"/>
                                                    <GradientStop Color="#FFD1D1D1" Offset="1"/>
                                                    <GradientStop Color="#FFDDE1E5" Offset="0.722"/>
                                                    <GradientStop Color="#FFDADEE2" Offset="0.983"/>
                                                </LinearGradientBrush>
                                            </Grid.Background>
                                            <CheckBox ToolTipService.ToolTip="Отметить все для удаления" x:Name="commonCheckBox" Checked="commonCheckBox_Checked" Unchecked="commonCheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                        </Grid>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </data:DataGridTemplateColumn.HeaderStyle>

                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox ToolTipService.ToolTip="Отметить для удаления" Loaded="CheckBox_Loaded" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" Tag="{Binding}"></CheckBox>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            
            <data:DataGridTextColumn Header="Пользователь" Binding="{Binding Path=UserName}" />

            <data:DataGridTemplateColumn Header="Дата и время">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock VerticalAlignment="Center" ToolTipService.ToolTip="число.месяц.год, часы:минуты">
                                <TextBlock.Text>
                                    <Binding Path="Date" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd.MM.yy, HH:mm" />
                                </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
        </classes:ColumnCollection>
    </navigation:Page.Resources>
    
    <Grid x:Name="LayoutRoot" Background="White">
        
        <Grid.Resources>
        </Grid.Resources>
        
        <StackPanel Orientation="Vertical">
            <StackPanel x:Name="buttonsPanel" Orientation="Horizontal">
                <Button IsEnabled="False" VerticalAlignment="Top" Margin="5,0,0,0" ToolTipService.ToolTip="Удалить" Width="24" Height="24" x:Name="deleteButton" Click="deleteButton_Click">
                    <Image Source="/AdminModule;Component/Images/Delete.png"></Image>
                </Button>

                <Button VerticalAlignment="Top" Margin="5,0,0,0" ToolTipService.ToolTip="Очистить журнал" Width="24" Height="24" x:Name="clearButton" Click="clearButton_Click">
                    <Image Source="/AdminModule;Component/Images/Trash.png"></Image>
                </Button>

                <StackPanel VerticalAlignment="Top" Orientation="Vertical">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Margin="5,0,0,0" Text="От:" HorizontalAlignment="Left"  VerticalAlignment="Center"></TextBlock>
                        <controls:DatePicker Loaded="DatePicker_Loaded" IsTodayHighlighted="True" Height="22" x:Name="fromDate" Margin="2,0,0,0" VerticalAlignment="Center" />
                    </StackPanel>

                    <StackPanel Margin="0,3,0,0" Orientation="Horizontal">
                        <TextBlock Margin="5,0,0,0" Text="до:" VerticalAlignment="Center"></TextBlock>
                        <controls:DatePicker Loaded="DatePicker_Loaded" IsTodayHighlighted="True"  Height="22" x:Name="toDate" Margin="2,0,0,0" VerticalAlignment="Center" />
                    </StackPanel>
                </StackPanel>

                <usercontrols:LogFilter VerticalAlignment="Top" Margin="5,0,0,0" x:Name="logFilter" />
                
                <Button VerticalAlignment="Top" Margin="5,0,0,0" ToolTipService.ToolTip="Загрузить / Обновить" Width="24" Height="24" HorizontalAlignment="Left" x:Name="filterButton" Click="filterButton_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/AdminModule;Component/Images/Refresh.png"></Image>
                    </StackPanel>
                </Button>

                <TextBlock Text="Группировка по:" Margin="5,0,0,0" VerticalAlignment="Top"></TextBlock>

                <StackPanel VerticalAlignment="Top" x:Name="answerGrouping" Margin="5,0,0,0" Orientation="Vertical" Visibility="Collapsed">
                    <CheckBox Checked="groupByDepartment_Checked" Unchecked="groupByDepartment_Checked" x:Name="groupByDepartment" Margin="0,2,0,0" Content="отделам" VerticalAlignment="Center"></CheckBox>
                    <CheckBox Checked="groupByCharacterisitc_Checked" Unchecked="groupByCharacterisitc_Checked" x:Name="groupByCharacterisitc" Margin="0,2,0,0" Content="показателям" VerticalAlignment="Center"></CheckBox>
                    <CheckBox Checked="groupByPerson_Checked" Unchecked="groupByPerson_Checked" x:Name="groupByPerson" Margin="0,2,0,0" Content="сотрудникам" VerticalAlignment="Center"></CheckBox>
                </StackPanel>

                <StackPanel VerticalAlignment="Top" x:Name="inputGrouping" Margin="5,0,0,0" Orientation="Vertical"  Visibility="Collapsed">
                    <CheckBox Checked="groupByUser_Checked" Unchecked="groupByUser_Checked" x:Name="groupByUser" Margin="0,2,0,0" Content="пользователю" VerticalAlignment="Center"></CheckBox>
                </StackPanel>
            </StackPanel>
        </StackPanel>

        <data:DataGrid Margin="0,60,0,0" x:Name="dataGrid" IsReadOnly="True" AutoGenerateColumns="False" SelectionMode="Single" Grid.ColumnSpan="2" RowStyle="{StaticResource NotSelectedDataGridRowStyle}" />
        <!--<data:DataPager x:Name="dataPager" AutoEllipsis="True" HorizontalAlignment="Center" VerticalAlignment="Bottom" DisplayMode="FirstLastPreviousNextNumeric" PageSize="{Binding Path=DataPager_PageSize, Source={StaticResource settings}}" Source="{Binding Path=ItemsSource, ElementName=dataGrid}"></data:DataPager>-->
        <usercontrols:ProgressBar IsVisibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="progressBar"></usercontrols:ProgressBar>
    </Grid>
</navigation:Page>
